﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Diagnostics;

using CRM.Controller;
using CRM.Entity.Extra;
using CRM.Entity;
using CRM.Common;

namespace CRM.Web.Page.Ajax
{
    /// <summary>
    /// UserTypeAjax 职员的相关操作类
    /// </summary>
    public class UserTypeAjax : IHttpHandler, IRequiresSessionState
    {
        UserTypeController userTypeController = new UserTypeController();

        public void ProcessRequest(HttpContext context)
        {
            string action = string.Empty;

            if (context.Request["action"] != null)
            {
                action = context.Request["action"];
            }

            switch (action)
            {
                case "ListFunc":
                    ListFunc(context);
                    break;
            }
        }


        /// <summary>
        /// 获取集合
        /// </summary>
        /// <param name="context"></param>
        private void ListFunc(HttpContext context)
        {
            var pageIndex = Convert.ToInt32(context.Request.Form["pageIndex"]);

            var pageSize = Convert.ToInt32(context.Request.Form["pageSize"]);

            var pageInfo = new PageInfo()
            {
                PageIndex = pageIndex,
                PageSize = pageSize
            };

            var userTypePage = userTypeController.GetList(pageInfo);

            if (userTypePage.ListEntity == null)
                userTypePage.ListEntity = new List<UserType>();

            context.Response.Write(JsonHelper.ListToJson(userTypePage.ListEntity, userTypePage.RecordCount.ToString()));

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}